import os
import threading
import time


def runappium(port='4723'):
    """

    :return:
    """
    cmd = r"appium -a 127.0.0.1 -p " + port
    # 阻塞
    os.popen(cmd).read()
    print("111")


# 创建一个子线程，叫th
th = threading.Thread(target=runappium, args=())
# 启动线程
th.start()
print("appium启动成功")
time.sleep(15)
print("关闭appium")


def stopappium(port='4723'):
    pid = os.popen('netstat -aon | findstr ' + port).read()
    pid = pid.split(' ')
    if len(pid) < 2:
        return
    else:
        pid = pid[len(pid)-1]

    res = os.popen('taskkill /F /PID ' + pid).read()
    print(res)
stopappium()
time.sleep(5)
print(1)
